package com.edevp.common.security.config;

import com.edevp.common.security.interceptor.AuthInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 校验token, 并把token绑定到线程本地变量中还有校验权限，不通过注解校验的权限，可以配置权限表
 * @author Blueeyedboy
 * @date 2022-07-06 5:00 PM
 **/

@Order(30)
@Configuration
@RequiredArgsConstructor
public class AuthWebMvcConfigurer implements WebMvcConfigurer {

	private final AuthProperties authProperties;

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		InterceptorRegistration interceptorRegistration = registry.addInterceptor(new AuthInterceptor())
				.addPathPatterns("/*/*/**");
		if(authProperties.getUrls() != null){
			interceptorRegistration.excludePathPatterns(authProperties.getUrls() );
		}
	}
}
